package com.maltys.dp;

/**
 * @author malty
 * @link <a href="https://leetcode.cn/problems/integer-break/">整数拆分</a>
 */
public class SplitInteger {
    public static void main(String[] args) {
        SplitInteger splitInteger = new SplitInteger();
        for (int i = 1; i <= 20; i++) {
            int aBreak = splitInteger.integerBreak(i);
            System.out.println(aBreak);
        }
    }

    /**
     *
     */
    public int integerBreak(int n) {
        int[] dp = new int[Math.max(n, 5) + 1];
        dp[1] = 1;
        dp[2] = 1;
        dp[3] = 2;
        dp[4] = 4;
        dp[5] = 6;
        if (n < 6) {
            return dp[n];
        }
        for (int i = 6; i <= n; i++) {
            for (int j = 1; j <= i; j++) {
                dp[i] = Math.max(dp[i], Math.max(dp[i - j], i - j) * j);
            }
        }
        return dp[n];
    }
}
